<?php
/** 
 * 个人中心
 * @package     soter
 * @author      高 <gaowenjie_xy@126.com>
 * @createTime  2015/05/12
 */
class Controller_Account extends Soter_Controller
{
    /**
     * 登录操作
     */
    public function do_login()
    {
        Sr::view()->load("Account/login");
    }

    /**
     * 登录提交操作
     */
    public function do_loginGo()
    {
        $inputEmail = Sr::post("inputEmail", "", true);
        $inputPassword = Sr::post("inputPassword", "", true);

        $rule=array(
            'inputEmail'=>array(
                'functions[strip_tags,trim]'=>'',
                'required'=>'邮箱不能为空',
            ),
            'inputPassword'=>array(
                'functions[strip_tags,trim]'=>'',
                'required'=>'密码不能为空',
            ),
        );

        $data = array(
            "inputEmail" => $inputEmail, 
            "inputPassword" => $inputPassword
        );

        $isOkay = Sr::checkData($data, $rule, $retData, $errorMessage);

        if (!$isOkay) 
        {
            Sr::redirect(Sr::Url("Account/login.do"), $errorMessage, 3, "Common/error");
        }

        $model = Sr::model("User");
        echo $model->loginDo();
    }

    /**
     * 注册操作
     */
    public function do_register()
    {
        $aUser = Sr::model("User");

        Sr::view()->load("Account/register");
    }

    /**
     * 
     */
    public function do_registerGo()
    {
        $inputEmail = Sr::post("inputEmail", "", true);
        $inputPassword = Sr::post("inputPassword", "", true);
        $repeatInputPassword = Sr::post("repeatInputPassword", "", true);

        $rule=array(
            'inputEmail'=>array(
                'functions[strip_tags,trim]'=>'',
                'required'=>'邮箱不能为空',
                'email' => "邮箱格式错误",
            ),
            'inputPassword'=>array(
                'functions[strip_tags,trim]'=>'',
                'required'=>'密码不能为空',
                'max_len[50]' => "密码长度能超过20",
                'match[repeatInputPassword]' => "两次输入密码不相等" 
            ),
            'repeatInputPassword'=>array(
                'functions[strip_tags,trim]'=>'',
                'required'=>'密码不能为空',
                'max_len[50]' => "密码长度能超过20",
            ),
        );

        $data = array(
            "inputEmail" => $inputEmail, 
            "inputPassword" => $inputPassword
        );

        $isOkay = Sr::checkData($data, $rule, $retData, $errorMessage, $errorKey);
        
        if (!$isOkay) 
        {
            Sr::redirect(Sr::Url("Account/login.do"), $errorMessage, 3, "Common/error");
        }
    }
}
?>